Skip to content

Conversation

@tshepang
Copy link
Member

No description provided.

bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 11, 2025
1826: FLS: Rust 1.89 and 1.90 updates r=Hoverbear a=tshepang

This includes these upstream changes:

- rust-lang/fls#579
- rust-lang/fls#580

Also included are some text fixes not strictly related to Rust compiler changes.

Co-authored-by: Tshepang Mbambo <tshepang.mbambo@ferrous-systems.com>
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 11, 2025
1826: FLS: Rust 1.89 and 1.90 updates r=Hoverbear a=tshepang

This includes these upstream changes:

- rust-lang/fls#579
- rust-lang/fls#580

Also included are some text fixes not strictly related to Rust compiler changes.

Co-authored-by: Tshepang Mbambo <tshepang.mbambo@ferrous-systems.com>
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 11, 2025
1826: FLS: Rust 1.89 and 1.90 updates r=Hoverbear a=tshepang

This includes these upstream changes:

- rust-lang/fls#579
- rust-lang/fls#580

Also included are some text fixes not strictly related to Rust compiler changes.

Co-authored-by: Tshepang Mbambo <tshepang.mbambo@ferrous-systems.com>
@traviscross
Copy link
Contributor

traviscross commented Oct 12, 2025

cc @PLeVasseur @nikomatsakis @joshtriplett

@tshepang tshepang force-pushed the tshepang/document-1.90 branch from a2ae9bd to a9fdd2d Compare October 16, 2025 13:24
Comment on lines 315 to 319
* :dp:`fls_zyuxqty09SDO`
All forms of :t:`[borrow]s` except those of expressions that would be subject to
:t:`drop scope extension`,
and which are either :t:`[mutable borrow]s`
or borrows of expressions that result in values with :t:`interior mutability`.
Copy link
Contributor

@traviscross traviscross Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things. One, it's OK for the expression to be subject to drop scope extension. It's not OK for that extension to extend the scope outside of the initializer to the end of the program.

const _: () = { let x = { &mut 0u8 }; x; }; //~ OK
//                             ^^^
// The drop scope of this temporary is extended.

Two, the comma in "..., and which are either..." causes me to read it as a clause independent from "except...". I.e., this says (applying commutativity) "all forms of borrows 1) that are either mutable or result in values with interior mutability and 2) where the expression would not be subject to drop scope extension".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@traviscross -- did this address the issue raised?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, except that, if I'm reading the diff correctly, it's putting this language in the list of what constitutes a constant context rather than about what constitutes a constant expression. We're defining constant expressions here, and the existing rules about "borrows" and "immutable borrow expressions" will need to be changed (and then that reflected in the changelog, etc.).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/values.rst Outdated
Comment on lines 98 to 100
:dp:`fls_ooOYxhVh8hZo`
The type of a :t:`constant` cannot be a :t:`mutable reference type`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things. One, even with the other rule, this needs to talk about containing a mutable reference rather than being one.

Two, it's not enough to talk about types here. We actually do this reasoning by value, not by type.

trait Tr {}
impl<T: ?Sized> Tr for T {}
static mut X: u8 = 0;
const _: &dyn Tr = unsafe { &&mut X }; //~ ERROR
//       ^^^^^^^
// This type does not contain any mutable references.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am not sure how to word this simply, given the complexities

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will give this a shot.

The paragraph

The type of a :t:constant cannot be a :t:mutable reference type.

should be removed.

Insert the following after
7.1:8 The value of a constant is determined by evaluating its constant initializer.

The value of a constant cannot contain any mutable references, except when:

  • The type of the constant is an immutable reference and the initializer contains a reference to a mutable static, or
  • The type of the constant is subject to interior mutability and the initializer contains a reference to a value subject to interior mutability, or
  • The type of the constant is a zero-sized type and the initializer contains a reference to a value of a zero-sized type, or
  • The initializer contains a reference to an external static.

I am not sure whether the type of the constant plays a role in the external static case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of a constant cannot contain any mutable references, except when... The initializer contains a reference to an external static.

unsafe extern "C" {
    safe static S1: u8;
}

static mut S2: u8 = 0;

const C: (&u8, &mut u8) = (&S1, unsafe { &mut S2 }); //~ ERROR
//                         ^^^
// The initializer contains a reference to an external static.

Copy link
Contributor

@traviscross traviscross Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly:

The value of a constant cannot contain any mutable references, except when... The type of the constant is an immutable reference and the initializer contains a reference to a mutable static...

static mut S1: u8 = 0;
static mut S2: u8 = 0;

const C: &(&u8, &mut u8) = unsafe { &(&S1, &mut S2) }; //~ ERROR
//       ^                            ^^^
// The type of the constant is an immutable reference and the
// initializer contains a reference to a mutable static.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tshepang Here is the wording we arrived at during our FLS team meeting on 2025-11-14:

The final value of a constant, after the constant initializer is evaluated to a value of the declared type, cannot contain any mutable references except when

  • The mutable reference is contained within an external static, or
  • The mutable reference is contained within a mutable static or a static whose type is subject to interior mutability, or
  • The mutable reference is contained within an union, or
  • The referent is a value of a zero-sized type.

Copy link
Member Author

@tshepang tshepang Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

70bef35

used "after type coercion" instead of "final value" (since the latter is not defined anywhere), then adjusted the sentence a bit due to that, so that it is more pleasant to read

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more thing, do we need the first part of the sentence, "After a constant initializer is evaluated to a value of the declared type", given that the sentence preceding it says "The value of a constant is determined by evaluating its constant initializer"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we do not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@traviscross
Copy link
Contributor

It looks like CI is broken related to:

@traviscross
Copy link
Contributor

I see that's fixed in:

@tshepang tshepang force-pushed the tshepang/document-1.90 branch from c8bb9c9 to 61b165e Compare November 15, 2025 01:46
@tshepang
Copy link
Member Author

tshepang commented Nov 15, 2025

Sadly had to rebase (due to ci fail that was later fixed), invalidating all links to commits in review responses. Should I squash it all?

@tshepang
Copy link
Member Author

oh, github actually preserves the links.. so kool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants